<ul class="breadcrumb">
  <li><a href="/">首页</a> <span class="divider">/</span></li>
  <li><a href="/students">学生信息</a> <span class="divider">/</span></li>
  <li class="active">
    <% if !@f_n.nil?&&!@f_n.empty? %>
        <%= @f_n %>
    <% else %>
        所有学生
    <% end %>
  </li>
</ul>
<p>
  <a style=" cursor: pointer" onclick="$('#filter_div').toggle('slow')">选择过滤条件</a> |
  <a href="/students">重置过滤条件</a> |
  <%= link_to '新建学生记录', new_student_path %>
</p>
<div id="filter_div" style="display: none">
  <form action="/students" method="get">
    <input type="hidden" name="type" value="s"/>

    <p>学号:<input type="text" name="i" style="width: 60px"/>&nbsp;&nbsp;姓名:<input type="text" name="x" style="width: 60px"/>&nbsp;&nbsp;年级:<input type="text" name="n" style="width: 60px"/>&nbsp;&nbsp;专业:<input type="text" name="z" style="width: 120px"/>
    </p>

    <p>
      大学:<%= select_tag "u", options_from_collection_for_select(Student.select("DISTINCT(university)"), "university", "university"), :multiple => true, :size=>5, :style=>"width:100px;vertical-align:text-top" %>&nbsp;
      院系:<%= select_tag "y", options_for_select([]), :multiple => true, :size=>5, :style=>"width:120px;vertical-align:text-top" %>&nbsp;
      分组:<%= select_tag "g", options_from_collection_for_select(Student.select("DISTINCT(sgroup)"), "sgroup", "sgroup"), :multiple => true, :size=>5, :style=>"width:100px;vertical-align:text-top" %>&nbsp;
    </p>

    <p>毕业时间:从<input type="text" name="s" style="width: 160px"/> 到 <input type="text" name="e" style="width: 160px"/></p>

    <p>
      生源地:<input type="text" name="d" style="width: 160px"/>&nbsp;性别:<%= select_tag "b", "<option value=\"\">不限</option><option value=\"0\">男</option><option value=\"1\">女</option>".html_safe, :style=>"width:60px" %>&nbsp;手机:<input type="text" name="p" style="width: 100px"/>&nbsp;
    </p>
    <input type="submit" class="btn primary" value="提交"/>
    <input type="reset" class="btn" value="清空"/>
  </form>
</div>
<script type="text/javascript">
    $("#u").change(function() {
        var v = "";
        $('option:selected', this).each(function() {
            v += ("," + this.value);
        });
        if (v == "") {
            $("#y").html("");
            return;
        }
        jQuery.ajax({
            url : "/get_college_by_university",
            dataType : "html",
            timeout : 1000,
            data : {
                content : v
            }
            ,
            success : function(data) {
                $("#y").html(data);
            }
            ,
            error : function(jqXHR, textStatus, errorThrown) {
                alert("程序出错,请重试")
            }
            ,
            complete : function() {
                isLoading = false;
            }
        });
    });
    var offSet = 1;
    var start = 30;
    var isLoading = false;
    var isEnd = <%= @f_n.nil?? "false":"true" %>;
    $(window).scroll(function() {
        // 并不是所有页面都要执行加载操作。
        // 你也可以选择别的识别条件。
        if (!isEnd) {
            //获取网页的完整高度(fix)
            //var hght = window.scrollHeight;
            var hght = document.documentElement.scrollHeight;
            //获取浏览器高度(fix)
            //var clientHeight = window.clientHeight;
            var clientHeight = document.documentElement.clientHeight;
            //获取网页滚过的高度(dynamic)
            var top = window.pageYOffset || (document.compatMode == 'CSS1Compat' ? document.documentElement.scrollTop : document.body.scrollTop);
            //当 top+clientHeight = scrollHeight的时候就说明到底儿了
            if (top >= (parseInt(hght) - clientHeight)) {
                //alert("as#d#f".replace(/#d#/, "f"));
                //document.write("\u7801\u5934");
                append_students();
            }
        }
    });
    function append_students() {
        if (isLoading && !isEnd) {
            return;
        }
        isLoading = true;
        jQuery.ajax({
            url : "/get_students4ajax",
            data : {
                offset : offSet  ,
                start : start
            },
            dataType : "html",
            timeout : 5000,
            success : function(data) {
                if (data == "end") {
                    isEnd = true;
                    return;
                }
                offSet++;
                start += 30;
                jQuery("tbody").append(data);
                $("table").trigger("update");
            },
            error : function(jqXHR, textStatus, errorThrown) {
                alert("程序出错,请重试");
            },
            complete : function() {
                isLoading = false;
            }
        });
    }
    $(document).ready(function() {
        $("table").tablesorter({
            sortList: [
                [1,0]
            ]  ,
            headers: { 0: { sorter: false},10: { sorter: false} }
        });
        (function() {
            var $backToTopTxt = "返回顶部", $backToTopEle = $('<div class="backToTop"></div>').appendTo($("body"))
                    .text($backToTopTxt).attr("title", $backToTopTxt).click(function() {
                        $("html, body").animate({ scrollTop: 0 }, 120);
                    }), $backToTopFun = function() {
                var st = $(document).scrollTop(), winh = $(window).height();
                (st > 0) ? $backToTopEle.show() : $backToTopEle.hide();
                //IE6下的定位
                if (!window.XMLHttpRequest) {
                    $backToTopEle.css("top", st + winh - 166);
                }
            };
            $(window).bind("scroll", $backToTopFun);
            $(function() {
                $backToTopFun();
            });
        })();
    });


</script>
<table class="zebra-striped bordered-table">
  <thead>
  <tr>
    <th>序号</th>
    <th>学号</th>
    <th>指纹</th>
    <th>姓名</th>
    <th>年级</th>
    <th>大学</th>
    <th>院系</th>
    <th>专业</th>
    <th>分组</th>
    <th>性别</th>
    <!--<th class="header">生源地</th>-->
    <!--<th class="header">毕业时间</th>-->
    <th>操作</th>
  </tr>
  </thead>
  <tbody>
  <% index =0 %>
  <% @students.each do |student| %>
      <tr>
        <% index =index+1 %>
        <td><%= index %></td>
        <td><%= student.studentId %></td>
        <td><%= student.fid %></td>
        <td><%= student.name %></td>
        <td><%= student.grade %></td>
        <td><%= student.university %></td>
        <td><%= student.college %></td>
        <td><%= student.major %></td>
        <td><%= student.sgroup %></td>
        <td><%= {0=>"男", 1=>"女"}[student.gender] %></td>
        <!--<td><%= student.studentAddr %></td>-->
        <!--<td><%= student.graduationTime.strftime("%Y/%m") if !student.graduationTime.nil? %></td>-->

        <td><%= link_to('出勤', "/student/attendance/"<<student.id.to_s) %>
          <%= link_to '成绩', "/student/scores/"<<student.id.to_s %>
          <%= link_to '详细', student %>
          <%= link_to '编辑', edit_student_path(student) %>
          <%= link_to '删除', student, confirm: '删除本学生信息同时会删除此学生所有课程的出勤信息和成绩信息!确认删除?', method: :delete %></td>
      </tr>
  <% end %>
  </tbody>
</table>

<br/>

